package cn.wind.xboot.module.web.controller;

import cn.wind.xboot.core.res.ApiResult;
import cn.wind.xboot.framework.domain.PageVo;
import cn.wind.xboot.logic.dto.BannerDto;
import cn.wind.xboot.logic.dto.BannerFeeDto;
import cn.wind.xboot.logic.entity.Banner;
import cn.wind.xboot.logic.entity.BannerArea;
import cn.wind.xboot.logic.service.IBannerAreaService;
import cn.wind.xboot.logic.service.IBannerService;
import cn.wind.xboot.module.app.v1.controller.BaseController;
import cn.wind.xboot.upload.OssUpload;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *轮播广告管理
 * @author WangHao
 * @date 2018-12-24
 */
@Slf4j
@RequestMapping("banner")
@Controller
public class BannerController extends BaseController {
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IBannerAreaService bannerAreaService;

    /**
     * 轮播图管理-列表展示
     * @param pageVo
     * @param vId 菜市场id
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public ApiResult list(PageVo pageVo,String showStart,String showEnd,Integer isPush,Integer vId){
        Map<String,Object> map= Maps.newHashMap();
        map.put("showStart",showStart);
        map.put("showEnd",showEnd);
        map.put("isPush",isPush);
        map.put("vId",vId);
        IPage<Banner> page = bannerService.findByCondition(pageVo.init(), map);
        return ApiResult.Custom().success(  ).add(page);
    }

    /**
     * 轮播图管理-新增
     */
    @RequestMapping("/add")
    @ResponseBody
    public ApiResult add(BannerDto bannerDto){
        Banner banner = new Banner();
        banner.setImg(bannerDto.getImg());
        banner.setH5(bannerDto.getH5());
        banner.setTitle(bannerDto.getTitle());
        banner.setShowStart(bannerDto.getShowStart());
        banner.setShowEnd(bannerDto.getShowEnd());
        banner.setDailyFee(bannerDto.getDailyFee());
        banner.setStatus(bannerDto.getStatus());
        banner.setSort(bannerDto.getSort());
        banner.setIsPush(bannerDto.getIsPush());
        banner.setPushStatus(bannerDto.getPushStatus());
        banner.setPushContent(bannerDto.getPushContent());
        bannerService.saveOrUpdate(banner);
        BannerArea bannerArea = new BannerArea();
        bannerArea.setBId(banner.getId());
        bannerArea.setVId(bannerDto.getVId());
        bannerAreaService.saveOrUpdate(bannerArea);
        return ApiResult.Custom().success("新增成功!");
    }

    /**
     * 轮播图管理-修改
     */
    @RequestMapping("/modify")
    @ResponseBody
    public ApiResult modify(Banner banner){
        bannerService.saveOrUpdate(banner);
        return ApiResult.Custom().success("修改成功!");
    }

    /**
     * 轮播图管理-删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ApiResult delete(Banner banner){
        bannerService.removeById(banner.getId());
        return ApiResult.Custom().success("删除成功!");
    }

    /**
     * 轮播图管理-禁用
     */
    @RequestMapping("/prohibit")
    @ResponseBody
    public ApiResult prohibit(Banner banner){
        bannerService.prohibitBanner(banner.getId());
        return ApiResult.Custom().success("禁用成功");
    }

    /**
     * 广告收入统计-今日
     */
    @RequestMapping("/countTodayFee")
    @ResponseBody
    public ApiResult countTodayFee(){
        List<BannerFeeDto> list  = bannerService.countTodayFee();
        return ApiResult.Custom().success(  ).add(list);
    }

    /**
     * 近一个星期的广告费
     */
    @RequestMapping("/countWeekFee")
    @ResponseBody
    public ApiResult countWeekFee(){
        List<BannerFeeDto> list = bannerService.countWeekFee();
        return ApiResult.Custom().success( ).add(list);
    }

    /**
     * 近一个月的广告收入
     */
    @RequestMapping("/countMonthFee")
    @ResponseBody
    public ApiResult countMonthFee(){
        List<BannerFeeDto> list = bannerService.countMonthFee();
        return ApiResult.Custom().success( ).add(list);
    }

    /**
     * 今年广告收入
     */
    @RequestMapping("/countYearFee")
    @ResponseBody
    public ApiResult countYearFee(){
        List<BannerFeeDto> list = bannerService.countYearFee();
        return ApiResult.Custom().success( ).add(list);
    }
}
